﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace MVCWeb.Helpers
{
    public class FileHelper
    {
        public static string GetFileSize(double? size)
        {
            try
            {
                if (size.HasValue)
                {
                    return (size.Value / 1024).ToString("N2");
                    
                }
                else
                {
                    return "0";
                }
            }
            catch
            {
                return string.Empty;
            }
        }

        public static string ConvertToSafeFilename(string filename)
        {
            filename = filename.Replace('"', '_');
            filename = filename.Replace('\'', '_');
            filename = filename.Replace('/', '_');
            filename = filename.Replace('?', '_');
            filename = filename.Replace('!', '_');
            filename = filename.Replace('@', '_');
            filename = filename.Replace('#', '_');
            filename = filename.Replace('$', '_');
            filename = filename.Replace('%', '_');
            filename = filename.Replace('^', '_');
            filename = filename.Replace('&', '_');
            filename = filename.Replace('*', '_');

            return filename;
        }
    }
}
